<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>系统登录日志</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        //----------------------------------------------------------------------
        Ext.define('LoginLog', {
          extend : 'Ext.data.Model',
          fields : [{name: 'id'},
            {
              name: 'employee_id'
            },{
              name: 'company_name',
              mapping:'company',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            },{
              name: 'department_name',
              mapping:'department',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            },{
              name: 'employee_name',
              mapping:'employee',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            }, {
              name: 'name'
            }, {
              name: 'password'
            }, {
              name: 'ip'
            }, {
              name: 'action_date'
            }, {
              name: 'description'
            },{
              name: 'created_at'
            }
          ]
        });

        var sysLoginLogDS = Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'LoginLog',
          proxy : {
            type : 'ajax',
            url : '/admin/getAllSysLoginLog',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          },
          pageSize:pageSize,
          autoLoad:true
        });
        
        var toolBar = Ext.create('Ext.toolbar.Paging', {
          pageSize: pageSize,
          store: sysLoginLogDS,
          displayInfo: true,
          displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
          emptyMsg: "没有记录",
          items:["-",{
              text: '删除',
              iconCls: 'remove',
              handler : function(){
                var record = sysLoginLogSM.getSelected;
                if (!record) {
                  return false;
                }
                sysLoginLogDS.remove(record);
              }
            }]
        })

        //生成要订单的产品的Grid
        var sysLoginLogGrid = Ext.create('Ext.grid.Panel', {
          title:'系统登录日志列表',
          store: sysLoginLogDS,
          columns : [Ext.create('Ext.grid.RowNumberer'),{
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '公司',
              dataIndex: 'company_name',
              width: 150
            },{
              header: '部门',
              dataIndex: 'department_name',
              width: 80
            },{
              header: '员工名称',
              dataIndex: 'employee_name',
              width: 80
            },{
              header: '登录时输入的名称',
              dataIndex: 'name',
              width: 110
            },{
              header: '登录时输入的密码',
              dataIndex: 'password',
              width: 110
            },{
              header: '登录者的IP',
              dataIndex: 'ip',
              width: 110
            },{
              header: '信息',
              dataIndex: 'description',
              width: 100
            },{
              header: '登录时间',dataIndex: 'action_date',renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            },{
              header: '日期',
              dataIndex: 'created_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            }],
          selModel :Ext.create('Ext.selection.CheckboxModel'),
          loadMask: true,
          width: screenWidth-170,
          height: 320,
          frame: true,
          tbar: toolBar
        });

        sysLoginLogGrid.on('itemdblclick', function(gridPanel, record,item,index,e,options){
          employeeId = sysLoginLogDS.getAt(index).get('employee_id');
          actionHxDS.removeAll();
          if (employeeId != null){
            var employeeName = sysLoginLogDS.getAt(index).get('employee_name');
            actionHxDS.getProxy().extraParams.employee_id = employeeId;
            actionHxDS.load();
            actionHxGrid.setTitle("用户："+employeeName+"的行为历史记录列表");
          }
        });
        
        //------------------------用户操作行为记录----------------------------------------------
        Ext.define('ActionHx', {
          extend : 'Ext.data.Model',
          fields : [{name: 'id'},
            {
              name: 'company_name',
              mapping:'company',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            },{
              name: 'department_name',
              mapping:'department',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            },{
              name: 'role_name',
              mapping:'role',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            },{
              name: 'employee_name',
              mapping:'employee',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            }, {
              name: 'action_params'
            },{
              name: 'created_at'
            }
          ]
        });

        var actionHxDS = Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'ActionHx',
          proxy : {
            type : 'ajax',
            url : '/admin/getAllActionHxes',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          },pageSize:pageSize
        });

        //生成要订单的产品的Grid
        var actionHxGrid = Ext.create('Ext.grid.Panel', {
          title:'用户行为历史记录列表',
          store: actionHxDS,
          columns : [Ext.create('Ext.grid.RowNumberer'),{
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '公司',
              dataIndex: 'company_name',
              width: 150
            },{
              header: '部门',
              dataIndex: 'department_name',
              width: 80
            },{
              header: '员工名称',
              dataIndex: 'employee_name',
              width: 80
            },{
              header: '角色',
              dataIndex: 'role_name',
              width: 80
            },{
              header: '参数',
              dataIndex: 'action_params',
              width: 600
            },{
              header: '操作时间时间',
              dataIndex: 'created_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            }],
          loadMask: true,
          width: screenWidth-170,
          height: dgHeight,
          frame: true,
          bbar: Ext.create('Ext.toolbar.Paging', {
            pageSize: pageSize,
            store: actionHxDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          }),
          tbar: [{
              text: '删除',
              iconCls: 'remove',
              handler : function(){
                var record = actionHxSM.getSelected;
                if (!record) {
                  return false;
                }
                actionHxDS.remove(record);
              }
            }]
        });

        //查询
        var name = Ext.create('Ext.form.field.Text', {
          fieldLabel: '登录名称',
          name: 'name',
          anchor: '80%'
        });
        
        var searchButton = Ext.create('Ext.Button', {
          text: '搜索',
          iconCls: 'finding',
          width:70,
          handler: function(){
            sysLoginLogDS.removeAll();
            
            sysLoginLogDS.getProxy().extraParams = queryFormPanel.getForm().getFieldValues();
            toolBar.moveFirst();  
          }
        });

        var clearButton = Ext.create('Ext.Button', {
          text: '清空',
          width:50,
          handler: function(){
            queryFormPanel.form.reset();
          }
        });

        var queryFormPanel = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 60,
            labelAlign: 'right'
          },
          width: screenWidth-165,
          frame : true,
          border:false,
          items: [{
              layout: 'column',
              xtype: 'container',
              items: [{
                  columnWidth: .2,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [name]
                }, {
                  columnWidth: .2,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [searchButton]
                }, {
                  columnWidth: .2,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [clearButton]
                }]
            } ]
        });
        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
          width: screenWidth-160,
          height: totalHeight,autoScroll:true,
          //html: '&lt;empty panel&gt;',
          //cls:'cellpadding:10',
          frame:false,
          layout: {type: 'table',columns:1},
          //bodyStyle: 'padding:15px;align:center',
          //listeners: {
          //expand: showAgileDiagram
          //},
          items:[queryFormPanel,sysLoginLogGrid,actionHxGrid]
        });
        workbenchPanel.render("login_log_list_workbench");
      })
    </script>
  </head>
  <body>
    <div id="login_log_list_workbench"></div>
  </body>
</html>
